#ifndef RENDERER_H
#define RENDERER_H

#include "capi/cef_app_capi.h"
#include "capi/cef_render_process_handler_capi.h"

#include "ipc/ipc_renderer.h"
#include "tools/hash_map.h"
#include "tools/log_util.h"
#include "logger.h"

// 渲染进程管理对象
typedef struct _renderer_app {
    cef_app_t cef_app;
    cef_render_process_handler_t renderer_process_handler;
} renderer_app;

void CEF_CALLBACK on_before_command_line_processing_render(struct _cef_app_t *self, const cef_string_t *process_type,
                                                           struct _cef_command_line_t *command_line);

void CEF_CALLBACK on_register_custom_schemes_render(struct _cef_app_t* self, struct _cef_scheme_registrar_t* registrar);
struct _cef_resource_bundle_handler_t* CEF_CALLBACK get_resource_bundle_handler_render(struct _cef_app_t* self);

// 获取渲染进程管理对象
struct _cef_render_process_handler_t *CEF_CALLBACK get_render_process_handler(struct _cef_app_t *self);

// 处理主进程消息
int CEF_CALLBACK on_process_message_received_render(struct _cef_render_process_handler_t *self, struct _cef_browser_t *browser,
                                             struct _cef_frame_t *frame, cef_process_id_t source_process,
                                             struct _cef_process_message_t *message);

void CEF_CALLBACK on_context_created(struct _cef_render_process_handler_t *self, struct _cef_browser_t *browser,
                                     struct _cef_frame_t *frame, struct _cef_v8_context_t *context);

void CEF_CALLBACK on_context_released(struct _cef_render_process_handler_t *self, struct _cef_browser_t *browser,
                                      struct _cef_frame_t *frame, struct _cef_v8_context_t *context);
void CEF_CALLBACK on_browser_destroyed(struct _cef_render_process_handler_t* self, struct _cef_browser_t* browser);

renderer_app *renderer_app_create_t();

#endif